/**
 * 系统服务管理相关 API
 */

import { get, post } from '@/utils/request'

/**
 * 需要重启的配置
 */
export interface PendingRestartConfig {
  configKey: string
  oldValue: string
  newValue: string
}

/**
 * 需要重启的配置响应
 */
export interface PendingRestartResponse {
  configs: PendingRestartConfig[]
  instructions: string
}

/**
 * 系统状态
 */
export interface SystemStatus {
  status: 'Running' | 'Stopping' | 'Stopped'
  uptime: string
  environment: string
  platform: string
  processId: number
  machineName: string
  dotnetVersion: string
}

/**
 * 重启检查请求
 */
export interface CheckRestartRequest {
  configKeys: string[]
}

/**
 * 重启检查响应
 */
export interface CheckRestartResponse {
  requiresRestart: boolean
  configsRequiringRestart: string[]
  message: string
}

/**
 * 获取需要重启的配置
 */
export function getPendingRestart(): Promise<PendingRestartResponse> {
  return get<PendingRestartResponse>('/api/SystemService/pending-restart')
}

/**
 * 优雅关闭服务
 */
export function gracefulShutdown(): Promise<{ message: string }> {
  return post<{ message: string }>('/api/SystemService/graceful-shutdown')
}

/**
 * 获取服务状态
 */
export function getSystemStatus(): Promise<SystemStatus> {
  return get<SystemStatus>('/api/SystemService/status')
}

/**
 * 检查是否需要重启
 */
export function checkRestartRequired(data: CheckRestartRequest): Promise<CheckRestartResponse> {
  return post<CheckRestartResponse>('/api/SystemService/check-restart-required', data)
}
